<template>
	<view>
		<!-- <nav-bar-sub></nav-bar-sub> -->
		<!-- 用于提示是否确认退出考试 -->
		<!-- {{examDetail}} -->
		<u-modal v-model="show" :content="content" :show-cancel-button="true" @confirm="handleConfirm"></u-modal>
		<!-- 渲染题目 -->
		<Answer :isReviewed='isReview' :examDetail='examDetail' @submit='handleCommit' @timeEnd='handleConfirm'
			@onChange='onChange'></Answer>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import examTest1 from '@/common/examTest_1.js';
	// import("@/common/examTest_1.js").then(data => {
	// 	that.$store.commit('setExamDetail', data.examTest1)
	// })
	import Answer from '@/components/dyw-answer/answer.vue';
	export default {
		data() {
			return {
				examDetail: examTest1.examTest1,
				show: false,
				content: '是否确认交卷',
				isReview: false,
			}
		},

		components: {
			Answer
		},
		methods: {
			/* 提交答案 显示再次确认*/
			handleCommit(questionList) {
				// 显示是否确认交卷
				this.show = true;
			},

			// 已确认进行答案提交
			handleConfirm() { // 进行交卷的api请求
				// 本地数据版

				// api版
				// let that = this
				// if (this.examType == 'exam') {
				// 	this.$api.commitExam(this.$store.state.examDetail.exam.id, this.$store.state.examDetail.recordId)
				// 		.then(res => {
				// 			console.log('交卷:', res);
				// 			that.$u.route('/pages/exam/examResultPage', {
				// 				recordId: that.$store.state.examDetail.recordId,
				// 				examType: 'exam'
				// 			})
				// 		})
				// } else if ((this.examType == 'paper') || (this.examType == 'know')) {
				// 	this.$api.commitPaper(this.$store.state.examDetail.exerciseId)
				// 		.then(res => {
				// 			console.log('交卷:', res);
				// 			that.$u.route('/pages/exam/examResultPage', {
				// 				exerciseId: that.$store.state.examDetail.exerciseId,
				// 				examType: 'paper',
				// 			})
				// 		})
				// } else if (this.examType == 'store') {
				// 	this.$api.commitExam(this.$store.state.examDetail.exam.id, this.$store.state.examDetail.recordId)
				// 		.then(res => {
				// 			console.log('交卷:', res);
				// 			that.$u.route('/pages/exam/examResultPage', {
				// 				recordId: that.$store.state.examDetail.recordId,
				// 				examType: 'exam'
				// 			})
				// 		})
				// } else if (this.examType == 'course') {
				// 	this.$api.commitCourse(this.$store.state.access_token, this.$store.state.examDetail.exerciseId)
				// 		.then(res => {
				// 			console.log('交卷:', res);
				// 			that.$u.route('/pages/exam/examResultPage', {
				// 				exerciseId: that.$store.state.examDetail.exerciseId,
				// 				examType: 'course',
				// 			})
				// 		})
				// } else {
				// 	console.log("提交的考试类型出错");
				// }
			},

			onChange(answer) { // 题目答案变化
				console.log(answer)
			}
		},
		onLoad(option) {
			// option 为上个页面传过来的参数
			console.log('exam_id:', option.id);
			// 	var that = this
			// 	if (option.examType == 'exam') {
			// 		// 理论考试
			// 		that.$api.enterExam(that.$store.state.access_token, option.id)
			// 			.then(res => {
			// 				console.log(res.values);
			// 				that.$store.state.examDetail = res.values
			// 				var quesModules = res.values.modules
			// 				// console.log(that.$store.state.examDetail);
			// 				// 提取出所有的题目
			// 				that.$api.ModifyQuesList(quesModules)
			// 			})
			// 	} else if (option.examType == 'paper') {
			// 		// 模拟考试
			// 		this.$api.paperStart(option.paperId)
			// 			.then(res => {
			// 				console.log('paperStart:', res);
			// 				that.$store.state.examDetail = res.values
			// 				console.log('paper examDetail:', res.values);
			// 				var quesModules = res.values.modules
			// 				that.$api.ModifyQuesList(quesModules)
			// 				console.log(that.$store.state.pracDetail);
			// 				console.log(that.$store.state.pracQuesList);
			// 			})
			// 	} else if (option.examType == 'know') {
			// 		// 知识点练习
			// 		const knowSearch = JSON.parse(decodeURIComponent(option.knowSearch));
			// 		console.log(knowSearch);
			// 		this.$api.startKnow(knowSearch)
			// 			.then(res => {
			// 				if (res.status == 1) {
			// 					// 获取知识点失败
			// 					this.$refs.uToast.show({
			// 						title: res.message,
			// 						type: 'error',
			// 						// icon: false,
			// 						url: '/pages/exam/pracIndexKnow'
			// 					})
			// 				} else {
			// 					console.log('开始知识点练习的请求结果:', res);
			// 					that.$store.state.examDetail = res.values
			// 					var quesModules = res.values.modules
			// 					that.$api.ModifyQuesList(quesModules)
			// 					console.log(that.$store.state.pracDetail);
			// 					console.log(that.$store.state.pracQuesList);
			// 				}
			// 			})
			// 	} else if (option.examType == 'course') {
			// 		this.$api.startTheory(that.$store.state.access_token, option.paperId)
			// 			.then(res => {
			// 				that.$store.state.examDetail = res.values
			// 				var quesModules = res.values.modules
			// 				that.$api.ModifyQuesList(quesModules)
			// 			})
			// 	} else {
			// 		console.log("考试类型错误，请输入正确的类型");
			// 		// return false
			// 	}
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #FFFFFF;
	}
</style>
